﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.BLL;
using Com.CMS263.PO;
using Com.CMS263.Util;
using System.IO;

namespace Com.CMS263.Web.manage.TvStation
{
    public partial class editTvStationPeople : System.Web.UI.Page
    {
        TVstationBLL tvBll = new TVstationBLL();
        public IList<TVstation> tvList = new List<TVstation>();
        public TvStationPeople tvp = new TvStationPeople();
        tvStationPeopleBLL tvPBll = new tvStationPeopleBLL();
        public int pageTv = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = int.Parse(Request["id"]);
            pageTv = int.Parse(Request["page"]);
            tvp = (TvStationPeople)tvBll.FindModelById("TvStationPeople", id);

            tvList = tvBll.FindList();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request["id"]);
            pageTv = int.Parse(Request["pageTv"]);
            tvPBll.tvP = (TvStationPeople)tvBll.FindModelById("TvStationPeople", id);

            tvPBll.tvP.Description = StringUtil.checkStr(Request["description"]);
            tvPBll.tvP.Name = StringUtil.checkStr(Request["Name"]);
            tvPBll.tvP.TvStationId = int.Parse(Request["TvStationId"]);
            tvBll.tv = (Com.CMS263.PO.TVstation)tvBll.FindModelById("TVstation", tvPBll.tvP.TvStationId);
            tvPBll.tvP.TvStationName = tvBll.tv.Name;
            //上传头像
            string strDay = DateTime.Now.ToString("yyyy-MM-dd");
            string savePath = Server.MapPath("/ArtUpFile/" + strDay);
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            string HeadPic = strDay + "/" + UpLoadFileUtil.UpLoadFile(Request.Files["HeadPic"], savePath);
            tvPBll.tvP.HeadPic = HeadPic;
            if (tvPBll.UpDate())
            {
                StringUtil.Alert("修改成功！", "tvStationPeopleList.aspx?page="+pageTv);
            }
            else
            {
                StringUtil.Alert("修改成功！", "-1");

            }
        }
    }
}
